// 获取常用时间
import dayjs from 'dayjs';

// 获取最近7天的日期范围
export const LAST_7_DAYS = [
  dayjs().subtract(7, 'day').format('YYYY-MM-DD'),
  dayjs().format('YYYY-MM-DD'),
];

export const LAST_30_DAYS = [
  dayjs().subtract(30, 'day').format('YYYY-MM-DD'),
  dayjs().subtract(1, 'day').format('YYYY-MM-DD'),
];

// 格式化日期
export const formatDate = (date: string | number | Date) => {
  return dayjs(date).format('YYYY-MM-DD');
};

// 获取日期范围
export const getDateRange = (type: 'week' | 'month' | 'year') => {
  const end = dayjs();
  let start;

  switch (type) {
    case 'week':
      start = end.subtract(7, 'day');
      break;
    case 'month':
      start = end.subtract(1, 'month');
      break;
    case 'year':
      start = end.subtract(1, 'year');
      break;
  }

  return [start.format('YYYY-MM-DD'), end.format('YYYY-MM-DD')];
};
